fix memory leaks writing garmin routes. (#1299)
authortsteven4 <13596209+tsteven4@users.noreply.github.com>
Sat, 20 Jul 2024 12:48:06 +0000 (06:48 -0600)
committerGitHub <noreply@github.com>
Sat, 20 Jul 2024 12:48:06 +0000 (06:48 -0600)
garmin.cc

index cea5e6c4d1e52d3c79201c73d9857cfbf3b73a23..29036fd3e41163a16fd0935bcb975e1e34a58576 100644 (file)
--- a/garmin.cc
+++ b/garmin.cc
@@ -981,7 +981,7 @@ GarminFormat::route_waypt_pr(const Waypoint* wpt)
 void
 GarminFormat::route_write()
 {
-  int n = 2 * route_waypt_count(); /* Doubled for the islink crap. */
+  const int n = 2 * route_waypt_count(); /* Doubled for the islink crap. */
 
   tx_routelist = (GPS_SWay**) xcalloc(n,sizeof(GPS_PWay));
   cur_tx_routelist_entry = tx_routelist;
@@ -998,6 +998,12 @@ GarminFormat::route_write()
   };
   route_disp_all(route_hdr_pr_lambda, nullptr, route_waypt_pr_lambda);
   GPS_Command_Send_Route(portname, tx_routelist, n);
+
+  for (int i = 0; i < n; i++) {
+    GPS_Way_Del(&tx_routelist[i]);
+  }
+  
+  xfree(tx_routelist);
 }
 
 void